package com.hmdp.service.impl;

import cn.hutool.json.JSON;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.hmdp.dto.Result;
import com.hmdp.entity.ShopType;
import com.hmdp.mapper.ShopTypeMapper;
import com.hmdp.service.IShopTypeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hmdp.utils.RedisConstants;
import lombok.RequiredArgsConstructor;
import org.springframework.data.redis.core.ListOperations;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 虎哥
 * @since 2021-12-22
 */
@Service
@RequiredArgsConstructor
public class ShopTypeServiceImpl extends ServiceImpl<ShopTypeMapper, ShopType> implements IShopTypeService {

    private final ShopTypeMapper shopTypeMapper;
    private final StringRedisTemplate stringRedisTemplate;


//    @Override
//    public List<ShopType> queryTypeList() {
//        //1 去redis中查询所有类型
//        ListOperations<String, String> shopTypeList = stringRedisTemplate.opsForList();
//        List<String> cacheShopTypeList = shopTypeList.range(RedisConstants.SHOP_TYPE_KEY, 0, -1);
//        //2 如果有，直接返回
//        if(CollectionUtils.isNotEmpty(cacheShopTypeList)){
//            List<ShopType> result = new ArrayList<>();
//            for(String shopTypeStr : cacheShopTypeList){
//                ShopType shopType = new ShopType();
//        }
//        //3 没有的话去mysql中查询
//
//        //4 mysql中没有返回错误
//
//        //5 mysql中有  写入redis中并返回
//    }
}
